﻿@using Aguacongas.TheIdServer.BlazorApp.Pages.Identity.Components

@page "/identityresource"
@page "/identityresource/{id}"

@inherits EntityModel<Entity.IdentityResource>


@if (Model == null)
{
    <PageLoading />
}
else
{
    <EditForm EditContext="EditContext" OnValidSubmit="HandleValidSubmit">
        <CascadingValue Value="HandleModificationState">
            <div class="row bg-light sticky-top">
                <div class="col">
                    @if (IsNew)
                    {
                        <AuthorizeText Id="name" Placeholder="identity id" @bind-Value="@Model.Id" />
                    }
                    else
                    {
                        <h3>@Id</h3>
                    }
                </div>
                <div class="col">
                    @if (!NonEditable)
                    {
                        <SaveButton />
                        @if (!IsNew)
                        {
                            <DeleteEntityButton EntityId="@Model.Id" DeleteConfirmed="DeleteEntity" />
                        }
                    }
                    @if (!IsNew)
                    {
                        <ExportButton EntityPath="@EntityPath" Request="@ExportRequest" />
                        <CloneButton />
                    }
                </div>
                <div class="col">
                    <Filter CssClass="mt-1" />
                </div>
                <div class="w-100"></div>
                <div class="col">
                    <ul class="list-inline text-lowercase">
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#claims" @onclick='() => ScrollTo("claims")' @onclick:preventDefault>@Localizer["claims"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#properties" @onclick='() => ScrollTo("properties")' @onclick:preventDefault>@Localizer["properties"]</a>
                        </li>
                    </ul>
                </div>
                <div class="w-100"></div>
                <FluentValidationValidator />
                <ValidationSummary class="col" />
            </div>
            <div class="entity-details">
                <div class="card mb-3">
                    <div class="card-body">
                        <div class="mb-3 row">
                            <label class="col col-form-label">
                            </label>
                            <div class="col-lg-10 col-sm-12">
                                <AuthorizeCheckbox Name="enabled" Label="@Localizer["enabled"]" @bind-Value="@Model.Enabled" />
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label class="col col-form-label">
                            </label>
                            <div class="col-lg-10 col-sm-12">
                                <AuthorizeCheckbox Name="required" Label="@Localizer["required"]" @bind-Value="@Model.Required" />
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label class="col col-form-label" for="displayName">
                                @Localizer["display name"]
                            </label>
                            <div class="col-lg-9 col-sm-12">
                                <AuthorizeText Id="displayName" Placeholder="@Localizer["display name"]" @bind-Value="@Model.DisplayName" MaxLength="200" />
                            </div>
                            <div class="col-1">
                                <button id="btnAddDisplayName" type="button" class="btn btn-primary btn-sm" @onclick="() => AddResource(Entity.EntityResourceKind.DisplayName)">
                                    <span class="oi oi-plus"></span>
                                </button>
                            </div>
                        </div>
                        <IdentityResources Collection="@Model.Resources" ResourceKind="@Entity.EntityResourceKind.DisplayName"></IdentityResources>
                        <div class="mb-3 row">
                            <label class="col col-form-label" for="description">
                                @Localizer["decription"]
                            </label>
                            <div class="col-lg-9 col-sm-12">
                                <AuthorizeTextArea Id="description" Placeholder="@Localizer["description"]" @bind-Value="@Model.Description" MaxLength="1000" />
                            </div>
                            <div class="col-1">
                                <button id="btnAddDescription" type="button" class="btn btn-primary btn-sm" @onclick="() => AddResource(Entity.EntityResourceKind.Description)">
                                    <span class="oi oi-plus"></span>
                                </button>
                            </div>
                        </div>
                        <IdentityResources Collection="@Model.Resources" ResourceKind="@Entity.EntityResourceKind.Description" />
                    </div>
                </div>
                <div id="claims" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["Claims"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <IdentityClaimTypes Model="@Model" />
                    </div>
                </div>
                <div id="properties" class="card mb-3">
                    <div class="card-header">
                        <EntitySubGridTitle Text="@Localizer["Properties"]" Collection="@Model.Properties" CreateModel="CreateProperty" />
                    </div>
                    <div class="card-body">
                        <IdentityProperties Collection="@Model.Properties" />
                    </div>
                </div>
            </div>
        </CascadingValue>
    </EditForm>
}
